package com.aos.erp.schools.service.car.impl;


import com.aos.erp.common.constant.GlobalConstant;
import com.aos.erp.schools.enums.student.IsDel;
import com.aos.erp.schools.mapper.car.CarPictureMapper;
import com.aos.erp.schools.model.car.CarPicture;
import com.aos.erp.schools.service.car.CarPictureService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service
public class CarPictureServiceImpl extends ServiceImpl<CarPictureMapper, CarPicture> implements CarPictureService {
    @Resource
    private CarPictureMapper carPictureMapper;


    public  List<Map<String, Object>> getInfo(String carId, String type) {
        Map<String, Object> params = new HashMap<>();
        params.put("isDel", IsDel.normal.getValue());
        params.put("type", type);
        params.put("carId", carId);
        List<CarPicture> lists = carPictureMapper.queryList(params);
        List<Map<String, Object>> listMap = new ArrayList<>();
        for (CarPicture carPicture : lists) {
            Map<String, Object> m = new HashMap<>();
            m.put("src", GlobalConstant.fileServiceUrl + "?id=" + carPicture.getFileId());//原图地址
            m.put("id", carPicture.getId());//图片id
            m.put("fileId",carPicture.getFileId());
            listMap.add(m);
        }
        return listMap;
    }
    public Map<String, Object> queryList(String carId, String type) {
        Map<String, Object> params = new HashMap<>();
        params.put("isDel", IsDel.normal.getValue());
        params.put("type", type);
        params.put("carId", carId);
        List<CarPicture> lists = carPictureMapper.queryList(params);
        Map<String, Object> map = new HashMap<>();
        map.put("title", "车辆图片");
        map.put("start", 0);
        List<Map<String, Object>> listMap = new ArrayList<>();
        for (CarPicture carPicture : lists) {
            Map<String, Object> m = new HashMap<>();
            m.put("src", GlobalConstant.fileServiceUrl + "?id=" + carPicture.getFileId());//原图地址
            m.put("pid", carPicture.getId());//图片id
            m.put("thumb", "");//缩略图地址
            m.put("alt", "图片名");//图片名
            listMap.add(m);
        }
        if (lists != null && lists.size() > 0) {
            map.put("data", listMap);
        } else {
            map.put("data", new ArrayList<>());
        }
        return map;
    }

   public  int updateObject(String fileId){
       CarPicture carPicture=new CarPicture();
       carPicture.setFileId(Long.valueOf(fileId));
       carPicture.setIsDel(Integer.valueOf(IsDel.del.getValue().toString()));
       carPicture.setUpdated(new Date());
       int  i= baseMapper.updateObject(carPicture);
       return  i;
   }
}